<?php
declare(strict_types=1);

namespace ServerApp\lib\server\http;

use ServerApp\lib\core\SHttpServer;
use Swoole\Server;
use WebApp\lib\config\Config;

/**
 * Class Http
 */
class Http extends SHttpServer
{
    private $func;
    /**
     * Conf constructor
     * @param string $module
     * @param bool $debug
     * @param IHttp $func1
     */
    public function __construct(string $module = '', $debug=false, IHttp $func1)
    {
        $this->func = $func1;

        parent::__construct($module, $debug);
    }

    /**
     * @return string
     */
    protected function getMaster(): string
    {
        return $this->func->getName() . "_m1";
    }

    /**
     * @return string
     */
    protected function getManager(): string
    {
        return $this->func->getName() . "_m2";
    }

    /**
     * @return string
     */
    protected function getWorker(): string
    {
        return $this->func->getName() . "_w";
    }

    /**
     * @return int
     */
    public function getPort(): int
    {
        return PORT;
    }

    /**
     * @return string
     */
    protected function getBind(): string
    {
        return "0.0.0.0";
    }

    /**
     * @return array
     */
    protected function getSetting(): array
    {
        return array_merge(
            Config::getConf('server.setting'),
            Config::getConf('server.children.' . SERVER_NAME)
        );
    }

    protected function Start(): void
    {
        tracker(I, 'master start');
    }

    protected function ManagerStart(): void
    {
        tracker(I, 'manager start');
    }

    /**
     * @param $server
     * @param $worker_id
     */
    protected function WorkerStart(Server $server, $worker_id): void
    {
        tracker(I, "WorkerStart $worker_id");
    }

    /**
     * @param $server
     * @param $fd
     */
    protected function Close(Server $server, $fd): void
    {
//        tracker(I, 'close');
    }

    /**
     * @param $server
     * @param $worker_id
     */
    protected function WorkerStop(Server $server, $worker_id): void
    {
        tracker(I, "WorkerStop $worker_id");
    }

    /**
     * @return bool
     */
    protected function isSsl(): bool
    {
        return false;
    }
}